Public Class DataSetHelper

    Public Shared Function selectDistinct(ByVal InputDataTable As DataTable) As DataTable

        Dim PurgedDataTable As DataTable = InputDataTable.Clone()
        Dim _Columns As DataColumn() = New DataColumn(PurgedDataTable.Columns.Count - 1) {}
        For i As Integer = 0 To InputDataTable.Columns.Count - 1
            _Columns(i) = PurgedDataTable.Columns(i)
        Next
        Dim _UniqueConstraint As New UniqueConstraint(_Columns)

        PurgedDataTable.Constraints.Add(_UniqueConstraint)
        For i As Integer = 0 To InputDataTable.Rows.Count - 1

            Try
                PurgedDataTable.ImportRow(InputDataTable.Rows(i))
                ' Keep quite 
            Catch ex As Exception
            End Try
        Next

        Return PurgedDataTable

    End Function

    Public Shared Function selectColumns(ByVal InputDataTable As DataTable, ByVal ColumnNames As String()) As DataTable

        Dim dt As DataTable = InputDataTable.Copy

        Dim dc As DataColumn
        For Each dc In InputDataTable.Columns
            If Array.IndexOf(ColumnNames, dc.ColumnName) < 0 Then
                dt.Columns.Remove(dc.ColumnName)
            End If
        Next

        Return dt

    End Function

End Class
